package com.x.gzcrm.service.impl;

import com.x.gzcrm.mapper.StuInfoMapper;
import com.x.gzcrm.model.CourseOrder;
import com.x.gzcrm.model.PageResult;
import com.x.gzcrm.model.StuInfo;
import com.x.gzcrm.service.IStuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
@Transactional
public class StuInfoServiceImpl implements IStuInfoService {

    @Autowired
    StuInfoMapper stuInfoMapper;

    @Override
    public PageResult<StuInfo> findPageResult(StuInfo condition, int page, int pageSize) {
        PageResult<StuInfo> result=new PageResult<>();
        result.setCode(0);

        /*
         查询参数先设置为空
         */
        Map<String ,Object> params =new HashMap<String, Object>();
        params.put("condition",condition);//模糊查询条件
        // select * from XXX limit 0,10
        params.put("start",(page-1)*pageSize);
        params.put("pageSize",pageSize);

        //获取总记录数据
        int totalCount = stuInfoMapper.findCountByMap(params);
        result.setCount(totalCount);
        //获取查询的数据
        List<StuInfo> list = stuInfoMapper.findListByMap(params);
        result.setData(list);
        return result;
    }

    @Override
    public void save(StuInfo stuInfo) {
        stuInfoMapper.insert(stuInfo);
    }

    @Override
    public void update(StuInfo stuInfo) {
        stuInfoMapper.update(stuInfo);
    }

    @Override
    public StuInfo findById(Integer id) {
        return  stuInfoMapper.findById(id);
    }

    @Override
    public void deleteById(Integer id) {
        stuInfoMapper.deleteById(id);
    }

}
